<template>
<header class="header">
    <h1>小黑记事本</h1>
    <input placeholder="请输入任务" class="new-todo" v-model="task" @keyup.enter="onSubmit"/>
    <button class="add" @click="onSubmit">添加任务</button>
</header>
</template>

<script>
import EventBus from '../utils/EventBus.js';


export default {
    data() {
        return {
            task:''
        }
    },
    methods: {
        onSubmit() {
            // if(this.task.trim()) {
            //     this.$emit('add',this.task)
            //     this.task = ''
            // }else {
            //     alert('请输入任务')
            // }
            //改造eventBus通信
            EventBus.$emit('add',this.task)
            this.task=''
        }

    }
}
</script>
